var t = getApp();

Page({
    data: {
        oblig: [],
        name: "obliga",
        key: "",
        partab: "",
        contractlist: [],
        condition: !1,
        bol: "",
        From: "",
        url: "",
        id: "",
        sessin: "",
        botomstyle: "flexrow"
    },
    onLoad: function(t) {
        this.setData({
            key: t.key,
            From: t.From,
            url: t.url,
            id: t.id,
            sessin: t.sessin
        }), "end" == t.key ? this.setData({
            botomstyle: "flexrow2",
            bol: !1
        }) : this.setData({
            botomstyle: "flexrow",
            bol: !0
        });
    },
    onShow: function() {
        var a = this.data.key, e = this.data.From;
        if (1 == e) i = wx.getStorageSync(a);
        if (2 == e) var i = t.globalData.htGet[a];
        "obliga" == a && this.setData({
            oblig: i,
            partab: "甲方义务"
        }), "obligb" == a && this.setData({
            oblig: i,
            partab: "乙方义务"
        }), "obligc" == a && this.setData({
            oblig: i,
            partab: "丙方义务"
        }), "end" == a && this.setData({
            oblig: i,
            partab: "其他条款"
        });
    },
    onReady: function() {
        wx.removeStorageSync("modelEnd");
    },
    deleta: function() {
        var t = wx.getStorageSync("obliga") || [];
        t.pop(), wx.setStorageSync("obliga", t), this.setData({
            oblig: t
        });
    },
    obligref: function() {
        var a = this.data.key, e = this.data.From, i = this.data.id, o = this.data.url, s = this.data.sessin;
        if ("end" == a) wx.redirectTo({
            url: "../../pages/SdraftObref/SdraftObref?key=" + a + "&From=" + e + "&id=" + i + "&url=" + o + "&sessin=" + s
        }); else {
            var r = this.data.condition, n = wx.getStorageSync("refcontractlist");
            if (this.setData({
                condition: !r
            }), n && n.length > 0) this.setData({
                contractlist: n
            }), (!t.globalData.refcontractlist || t.globalData.refcontractlist.length < 1) && wx.request({
                url: t.url + "addon/Oblig/Oblig/oblightList",
                data: {},
                method: "GET",
                header: {
                    "Content-Type": "application/json",
                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                },
                success: function(a) {
                    var e = a.data.sort(function(t, a) {
                        return t.indexNo.localeCompare(a.indexNo);
                    });
                    t.globalData.refcontractlist = e, wx.setStorageSync("refcontractlist", e);
                }
            }); else {
                var l = this;
                wx.showToast({
                    title: "数据加载中",
                    icon: "loading",
                    duration: 2e4
                }), wx.request({
                    url: t.url + "addon/Oblig/Oblig/oblightList",
                    data: {},
                    method: "GET",
                    header: {
                        "Content-Type": "application/json",
                        Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                    },
                    success: function(a) {
                        wx.hideToast();
                        var e = a.data.sort(function(t, a) {
                            return t.indexNo.localeCompare(a.indexNo);
                        });
                        l.setData({
                            contractlist: e
                        }), t.globalData.refcontractlist = e, wx.setStorageSync("refcontractlist", e);
                    },
                    fail: function(t) {
                        wx.hideToast();
                        var a = wx.getStorageSync("refcontractlist");
                        l.setData({
                            contractlist: a
                        }), a || wx.showToast({
                            title: "无法连接网络",
                            icon: "loading",
                            duration: 2e3
                        });
                    }
                });
            }
        }
    },
    delet1: function(t) {
        var a = t.target.dataset.id, e = this.data.key, i = this;
        wx.showModal({
            title: "提示",
            content: "确定要删除吗？",
            success: function(t) {
                if (t.confirm) {
                    var o = wx.getStorageSync(e) || [];
                    o.splice(a, 1), wx.setStorageSync(e, o), i.setData({
                        oblig: o
                    });
                }
            }
        });
    },
    delet2: function(a) {
        var e = a.target.dataset.id, i = this.data.key, o = this;
        wx.showModal({
            title: "提示",
            content: "确定要删除吗？",
            success: function(a) {
                if (a.confirm) {
                    var s = t.globalData.htGet[i] || [];
                    s.splice(e, 1), t.globalData.htGet[i] = s, t.globalData.alternot = 1, o.setData({
                        oblig: s
                    });
                }
            }
        });
    },
    DelItem: function(t) {
        var a = this.data.From;
        1 == a && this.delet1(t), 2 == a && this.delet2(t);
    },
    backtoTable: function() {
        var t = this.data.From, a = this.data.id, e = this.data.url, i = this.data.sessin;
        1 == t && wx.redirectTo({
            url: "../../pages/SdrafTable/SdrafTable"
        }), 2 == t && wx.redirectTo({
            url: "../../pages/MyShtedit/MyShtedit?id=" + a + "&url=" + e + "&sessin=" + i
        });
    },
    openDetail: function(t) {
        var a = t.target.dataset.index, e = this.data.contractlist[a].id, i = this.data.key, o = this.data.From, a = this.data.id, s = this.data.url, r = this.data.sessin;
        wx.redirectTo({
            url: "../../pages/SdraftObref/SdraftObref?id=" + e + "&key=" + i + "&From=" + o + "&id=" + e + "&url=" + s + "&sessin=" + r + "&index=" + a
        });
    },
    packUp: function() {
        this.setData({
            condition: !1
        });
    }
});